<template>
  <!--模态窗 多行-->
  <transition
    name="custom-classes-transition"
    enter-active-class="animated fadeInDown"
    leave-active-class="animated fadeOutUp"
  >
    <div class="modal-ctrl-body" v-show="RevampModalObj.isShow">
      <div class="modal-ctrl-main odd-row-ctrl">

        <div class="modal-title">
          <p>修改线资源信息</p>
        </div>

        <div class="modal-ctrl-content">

          <div class="modal-row" >
            <div class="modal-form-key f-l indispensable">
              线对象编码：
            </div>
            <input type="text" maxlength="32" placeholder="最长32个字符" v-model="ModalData.linecode" class="modal-text f-l">
          </div>

          <div class="modal-row" >
            <div class="modal-form-key f-l indispensable">
              名称：
            </div>
            <input type="text" maxlength="64" placeholder="最长64个字符" v-model="ModalData.name" class="modal-text f-l">
          </div>

          <div class="modal-row" >
            <div class="modal-form-key f-l indispensable">
              所属单位：
            </div>
            <input type="text" v-model="stationName" @click="getStationTree" readonly="readonly" class="modal-text f-l" >
            <input type="hidden" v-model="ModalData.stationid">
            <div class="sectionTree" v-show="sectionTreeIShow">
              <div id="sectionRevampTree" class="ztree sectionTree-box"></div>
            </div>
          </div>

          <div class="modal-row" >
            <div class="modal-form-key f-l indispensable">
              等级：
            </div>
            <input type="text" maxlength="2" placeholder="最长2个字符" v-model="ModalData.objlevel" class="modal-text f-l">
          </div>

          <div class="modal-row" >
            <div class="modal-form-key f-l">
              资源类型编码：
            </div>
            <input type="text" readonly="readonly" v-model="ModalData.resourceTypeCode" class="modal-text f-l">
          </div>

          <div class="modal-row" >
            <div class="modal-form-key f-l">
              备注：
            </div>
            <input type="text" maxlength="500" placeholder="最长500个字符" v-model="ModalData.remark" class="modal-text f-l">
          </div>

        </div>
        <div class="btns text-r">
          <button type="button" class="btn btn-default" @click="close">取消</button>
          <button type="button" class="btn btn-info" @click="subBtn">确定</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
    export default {
        name: "AddOldLineModal",
        props:["RevampModalObj","selectRowId"],
        data(){
          return{
            ModalData:{
              linecode:'', //线对象编码
              name:'', //名称
              objlevel:'', //等级
              resourceTypeCode:'巡控线路',//资源类型编码
              remark:'',//备注
              stationid:""
            },
            carTypeList:[],
            stationName:'',
            setting : {
              data: {
                simpleData: {
                  enable: true
                },
              }
            },
            sectionTreeIShow:false
          }
        },
        mounted(){
          let _this = this;
          this.setting.callback = {
            onClick:function(event,treeId,treeNode){ //新增警员部门树选择
              //console.log(treeNode);
              _this.ModalData.stationid = treeNode.id;
              _this.stationName = treeNode.name;
              _this.sectionTreeIShow = !_this.sectionTreeIShow;
            }
          };
        },
      watch:{
        RevampModalObj:{
          handler(v1){
            if( v1.isShow ){
              this.selectId = this.selectRowId;
              this.getDotData();
            }
          },
          deep:true
        }
      },
        methods:{
          //资源详细信息
          getDotData(){
            //GET /resource/mapline/id/{id}
            this.$axios.get(this.DotCtrl+"/resource/mapline/id/"+this.selectId)
              .then(data=>{
                //console.log(data);

                let successData = data.data;
                for( let successKey in successData ){
                  for( let ModalDataKey in this.ModalData ){

                    if( successKey === ModalDataKey ){
                      this.ModalData[ModalDataKey] = successData[successKey];
                    }else if( successKey === "stationName" ){
                      this.stationName = successData[successKey];
                    }
                  }
                }

                //console.log(this.ModalData);
              })
              .catch(err=>{
                //console.log(err);
              })
          },
          //提交
          subBtn(){
             //console.log(this.ModalData);
            //return false;
            if( this.verifyForm.isNull(this.ModalData.linecode) ){
              this.s_alert("线对象编码不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.name) ){
              this.s_alert("名称不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.stationid) ){
              this.s_alert("所属单位不能为空！");
              return false;
            }
            else if( this.verifyForm.isNull(this.ModalData.objlevel) || this.verifyForm.isNumber(this.ModalData.objlevel) ){
              this.s_alert("等级为空或不是整数！");
              return false;
            }
            this.$axios.put(this.DotCtrl+"/MapLine/putMapLine/"+this.selectId,this.ModalData)
              .then((data)=>{
                //console.log(data);
                this.s_alert("修改成功！");
                this.close();
              })
              .catch((err)=>{
                this.s_alert("修改失败！");
                //console.log(err);
              })
          },
          //是否在线
          selectIsOnline(ele){
            ////console.log(ele.target.value);
            this.ModalData.isonline = ele.target.value;
          },
          selectCameraType(ele){
            ////console.log(ele.target.value);
            this.ModalData.category = ele.target.value;
          },
          attrTable(ele){
            ////console.log(ele.target.value);
            this.ModalData.code = ele.target.value
          },
          //展开部门树
          getStationTree(){
            this.sectionTreeIShow = !this.sectionTreeIShow;
            if( this.sectionTreeIShow ){
              this.getStationTreeAjax()
            }
          },
          //加载部门树
          getStationTreeAjax(){
            this.$axios.get(this.HOST+'/station/getOrgaInfo')
              .then((data)=>{
                $.fn.zTree.init($("#sectionRevampTree"), this.setting, data.data.data);
                //console.log(data);
              })
              .catch((err)=>{
                //console.log(err);
              })
          },
          //关闭弹窗
          close(){
            this.$emit("closeRevampModal");
            this.clearData(); //关闭弹窗清除数据
          },
          //清除数据
          clearData(){
            this.ModalData={
              linecode:'', //线对象编码
              name:'', //名称
              objlevel:'', //等级
              resourceTypeCode:'巡控线路',//资源类型编码
              remark:'',//备注
              stationid:""
            };
            this.stationName='';
          }
        },
    }
</script>

<style scoped>
  .sectionTree{
    position: absolute;
    top: 30px;
    right: 0;
    width: 80%;
    z-index: 2;
    background-color: #fff;
    border:1px solid rgba(51,51,51,0.2);
    box-sizing: border-box;
    padding: 5px;
    max-height: 200px;
    overflow-y: auto;
  }
  .fadeInDown,.fadeOutUp{
    animation-duration: .500s;
  }
  .form-control {
    height: 100%;
    border: 1px solid #ccc;
  }
</style>
